<!doctype html>
<html>

<head>
  <title></title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
  <link rel="stylesheet" href="../res/css/weui.css" />
  <link rel="stylesheet" href="../res/css/weuix.css" />
  <link rel="stylesheet" href="../res/css/common.css" />
  <script src="../res/js/zepto.min.js"></script>
  <script src="../res/js/zepto.weui.js"></script>
  <script src="../res/js/common.js?v=1"></script>
  <script>
    var doctor_id = getQst("doctor_id");
    var y, m;
	 var dayArr = 0;
    //设置日历的标题
    function setCalendarTitle(obj) {
      var year = obj.getFullYear();
      var month = obj.getMonth() + 1;
      var title = "" + year + "年" + month + "月";
      y = year;
      m = month;
      $('#idCalendarYear').html(year);
      $('#idCalendarMonth').html(month);
      var now = new Date(year, month - 1, 1);
      calculateDay(now);
    }

    //计算当前月份有几天，第一天是星期几
    function is_leap(year) {
      return (year % 100 == 0 ? res = (year % 400 == 0 ? 1 : 0) : res = (year % 4 == 0 ? 1 : 0));
    }

    function day(year) {
      mDays = new Array(31, 28 + is_leap(year), 31, 30, 31, 31, 30, 31, 30, 31, 30, 31);
      return mDays;
    }

    function calculateDay(obj) {
      dayArr = day(obj.getFullYear());
      var dayNum = dayArr[obj.getMonth()];
      var dayFirst = obj.getDay(); //0是星期天， 6是星期六
      var firstRow;
      if (dayFirst != 0) {
        firstRow = 8 - dayFirst; //第一行有日期的单元格个数,从右边数
      } else {
        firstRow = 1;
      }
      var firstRowBlank = 7 - firstRow; //第一行空的个数
      var lastRow = (dayNum - firstRow) % 7; //最后一个有日期的单元格个数
	  if(lastRow==0){
		  lastRow=7
	  }
      var lastRowBlank = 7 - lastRow;
      var RowNum = (dayNum - firstRow - lastRow) / 7 + 2;
      renderCalendar(RowNum, firstRow, firstRowBlank, lastRow, lastRowBlank);
    }

    function renderCalendar(RowNum, firstRow, firstRowBlank, lastRow, lastRowBlank) {
      var strCalendar = '';
      var i = 1;
      var j = 1;
      for (; i <= RowNum; i++) {
        if (i == 1) {
          strCalendar += '<tr>';
          while (firstRowBlank > 0) {
            strCalendar += '<td ></td>';
            firstRowBlank--;
          }
          while (firstRow > 0) {
            strCalendar += '<td class="onToday" id="'+j+'"><div>' + j + '</div></td>';
            j++;
            firstRow--;
          }
        } else if (i == RowNum && lastRow > 0) {
          strCalendar += '</tr><tr>';
          while (lastRow > 0) {
            strCalendar += '<td class="onToday" id="'+j+'"><div>' + j + '</div></td>';
            j++;
            lastRow--;
          }
          while (lastRowBlank > 0) {
            strCalendar += '<td></td>';
            lastRowBlank--;
          }
        } else {
          var day = 7;
          strCalendar += '</tr><tr>';
          while (day > 0) {
            strCalendar += '<td class="onToday" id="'+j+'"><div>' + j + '</div></td>';
            j++;
            day--;
          }
        }
      }
      strCalendar += '</tr>';
      $('#idCalendar').html(strCalendar);
	  showdata()
    }

    //读取系统当前时间，设置
    function initiate() {
      var now = new Date();
      setCalendarTitle(now);
    }

    function forwardMoth() {
      var forward = document.getElementById("idCalendarNext");
      forward.onclick = function () {
        var year = y;
        var month = m;
        if ((month + 1) <= 12) {
          var newDate = new Date(year, month, 1);
          setCalendarTitle(newDate);
        } else {
          var newDate = new Date(year + 1, 0, 1);
          setCalendarTitle(newDate);
        }
      }
    }

    function backMonth() {
      var back = document.getElementById("idCalendarPre");
      back.onclick = function () {
        var year = y;
        var month = m;
        if ((month - 1) >= 1) {
          var newDate = new Date(year, month - 2, 1);
          setCalendarTitle(newDate);
          m = month - 1;
        } else {
          var newDate = new Date(year - 1, 11, 1);
          setCalendarTitle(newDate);
          m = 12;
        }
      }
    }

    function showdata() { //2222
      var date = y + '-' + (m >= 10 ? m : "0" + m)
      var jsonData = {
        "doctorId": parseInt(doctor_id),
        "schedulingDate": date,
        //				"num" : num
      }
      newAjaxPost('/h5/doctorScheduling/getDoctorSchedulingListPc', jsonData, getDoctorScheduling)
      return
    }
    //获取值班数据
    //  var myday = []; //需要值班的数组
    var myday2 = []; //值班时间点
    function getDoctorScheduling(res) {
      myday2 = res.data.list;
	  let infoList = [];
      var num1 = 0;
	  $(".info").html('')
      for (var i = 0; i < myday2.length; i++) {
        if (myday2[i].isMorning == '1' || myday2[i].isAfternoon == '1' || myday2[i].isNight == '1') {
          num1++;
          //        myday.push(formatDate(myday2[i].time));
          myday2[i].num1 = myday2[i].schedulingDate.substr(8,2)
        }
      }
	  if(num1==0){
	  	$(".info").append('<div class="info_content" style="text-align:center">暂无医生排班信息</div>');
	  }
      $.each(myday2, function (e, item) {
        if (item.num1 != undefined) {
			//  isMorning 上午   0否 1是    isAfternoon 下午   0否 1是 isNight 晚上   0否 1是
			var i=item.num1-1
            if (item.isMorning == "1" && item.isAfternoon == "1" && item.isNight == "1") {
				// $("#"+item.num1+" div").eq(e).append('').addClass("workTime");
				 $(".onToday div").eq(i).append('').addClass("workTime");
				 $(".info").append('<div class="info_content"><div class="info_isonline">上午 下午 晚上</div><div class="info_time">'+item.schedulingDate+'</div></div>')
              // $(".onToday").eq(e).append('<text><span>上午</span><span>下午</span><span>晚上</span></text>').addClass("workTime");
            } else if (item.isMorning == "1" && item.isAfternoon == "1") {
				 $(".onToday div").eq(i).append('').addClass("workTime");
				 $(".info").append('<div class="info_content"><div class="info_isonline">上午 下午</div><div class="info_time">'+item.schedulingDate+'</div></div>')
              // $(".onToday").eq(e).append('<text><span>上午</span><span>下午</span></text>').addClass("workTime");
            } else if (item.isMorning == "1" && item.isNight == "1") {
				 $(".onToday div").eq(i).append('').addClass("workTime");
				 $(".info").append('<div class="info_content"><div class="info_isonline">上午 晚上</div><div class="info_time">'+item.schedulingDate+'</div></div>')
              // $(".onToday").eq(e).append('<text><span>上午</span><span>晚上</span></text>').addClass("workTime");
            } else if (item.isAfternoon == "1" && item.isNight == "1") {
				 $(".onToday div").eq(i).append('').addClass("workTime");
				 $(".info").append('<div class="info_content"><div class="info_isonline">下午 晚上</div><div class="info_time">'+item.schedulingDate+'</div></div>')
              // $(".onToday").eq(e).append('<text><span>下午</span><span>晚上</span></text>').addClass("workTime");
            } else if (item.isMorning == "1") {
				 $(".onToday div").eq(i).append('').addClass("workTime");
				 $(".info").append('<div class="info_content"><div class="info_isonline">上午</div><div class="info_time">'+item.schedulingDate+'</div></div>')
              // $(".onToday").eq(e).append('<text><span>上午</span></text>').addClass("workTime");
            } else if (item.isAfternoon == "1") {
				 $(".onToday div").eq(i).append('').addClass("workTime");
				 $(".info").append('<div class="info_content"><div class="info_isonline">下午</div><div class="info_time">'+item.schedulingDate+'</div></div>')
              // $(".onToday").eq(e).append('<text><span>下午</span></text>').addClass("workTime");
            } else if (item.isNight == "1") {
				 $(".onToday div").eq(i).append('').addClass("workTime");
				 $(".info").append('<div class="info_content"><div class="info_isonline">晚上</div><div class="info_time">'+item.schedulingDate+'</div></div>')
              // $(".onToday").eq(e).append('<text><span>晚上</span></text>').addClass("workTime");
            }
        }
      })
    }

    function formatDate(date) {
      var startDate = date;
      startDate = startDate.replace(new RegExp("-", "gm"), "/");
      var startDateM = (new Date(startDate)).getTime(); //得到毫秒数
      var time = parseFloat(startDateM) / 1000; //先将毫秒转化成秒
      return time;
    }

    $(function () {
      initiate();
      forwardMoth();
      backMonth();
      // showdata();

      //返回上页
      $(document).on("click", "#btnHeadBack", function () {
        goPageNo(-1);
      });
    });
  </script>
  <style>
	.weui-table td, .weui-table th, table td, table th{border: 0;}
	thead{background-color: #F8FBFF;}
    .flex {
      display: -webkit-box;
      display: box;
      display: -webkit-flex;
      display: -ms-flexbox;
      display: flex
    }
	.year-month{
		height: 50px;
		line-height: 50px;
	}
	#idCalendarPre{
		height: 30px;
		margin: auto;
		margin-right: 0;
	}
	#idCalendarNext{
		height: 30px;
		margin: auto;
		margin-left: 0;
	}
    .flex-pack-center {
      -webkit-box-pack: center;
      -webkit-justify-content: center;
      -ms-flex-pack: center;
      justify-content: center
    }

    .tbCalendar {
      background: #ffffff;
      margin: 10px;
	  border-radius: 10px;
	  overflow: hidden;
    }

    .tbCalendar td {
      text-align: center
    }

    .workTime {
		color: white;
		background-color: #1189ff;
		position: relative;
		border-radius: 20px;
		width: 25px;
		height: 25px;
		margin: 0 auto;
		font-size: 14px;
    }
	
	.info{padding: 0 10px;}
	.info_content{
		border-bottom: 1px solid #E0E0E0;
		padding: 10px 0;
	}
	.info_content:last-child{
		border-bottom: 0px;
	}
	.info_isonline{display: inline-block;}
	.info_time{
		display: inline-block;
		float: right;
		color: #353535;
	}
  </style>
</head>

<body>
  <div class="fix-top">
    <div class="weui-btn_primary weui-header">
      <div id="btnHeadBack" class="weui-header-left"><a class="icon icon-109"></a></div>
      <h1 class="weui-header-title">值班计划</h1>
    </div>
  </div>
  
  <div class="tbCalendar">
	  <div id="toyear" class="flex flex-pack-center">
	    <div title="上一个月" id="idCalendarPre"><img src="../res/images/icon_left.png" ></div>
	    <div class="year-month">&nbsp;<span id="idCalendarYear">2020</span>年<span id="idCalendarMonth">2</span>月&nbsp;
	    </div>
	    <div title="下一个月" id="idCalendarNext"><img src="../res/images/icon_right.png" ></div>
	  </div>
    <table>
      <thead>
        <tr>
          <td>一</td>
          <td>二</td>
          <td>三</td>
          <td>四</td>
          <td>五</td>
          <td style="color:#e70000">六</td>
          <td style="color:#e70000">日</td>
        </tr>
      </thead>
      <tbody id="idCalendar">
      </tbody>
    </table>
  </div>
  
  <div class="tbCalendar info">
	  <!-- <div class="info_content"><div class="info_isonline">早上 中午 晚上</div><div class="info_time">2020-12-12 12:12:12</div></div>
	  <div class="info_content"><div class="info_isonline">早上 中午 晚上</div><div class="info_time">2020-12-12 12:12:12</div></div> -->
  </div>
</body>

</html>